package com.lphj.datainterface.handle;

import com.lphj.datainterface.component.Config.ReadOtherConfig;
import com.lphj.datainterface.entity.TGoods;
import com.lphj.datainterface.entity.TStoreGoods;
import com.lphj.datainterface.service.TStoreGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;


@Component
public class TStoreGoodsHandle {


    @Autowired
    ReadOtherConfig readOtherConfig;

    @Autowired
    TStoreGoodsService tStoreGoodsService;

    /**
     *分公司商品维护
     * @param tGoods
     * @return
     */
    @Transactional
    public int addTStoreGoods(TGoods tGoods) {
        //清空tStoreGoods
        tStoreGoodsService.delTStoreGoods();
        int count = 0;
        if(tGoods != null) {
            TStoreGoods tStoreGoods = new TStoreGoods();
            tStoreGoods.setsStoreNO(readOtherConfig.getStoreNO());
            tStoreGoods.setnGoodsID(tGoods.getGoodsID());
            tStoreGoods.setsGoodsNO(tGoods.getGoodsNO());
            tStoreGoods.setsGoodsDesc(tGoods.getGoodsDesc());
            tStoreGoods.setsGoodsName(tGoods.getGoodsName());
            tStoreGoods.setsSpec(tGoods.getSpec());
            tStoreGoods.setnCategoryID(tGoods.getCategoryID());
            tStoreGoods.setnDeptID(readOtherConfig.getDept());
            tStoreGoods.setsGoodsTypeID(tGoods.getGoodsTypeID());
            tStoreGoods.setsGoodsTYpe(tGoods.getGoodsType());
            tStoreGoods.setsTradeModeID(tGoods.getTradeModeID());
            tStoreGoods.setsTradeMode(tGoods.getTradeMode());
            tStoreGoods.setsUnitID(tGoods.getUnitID());
            tStoreGoods.setsUnit(tGoods.getUnit());
            tStoreGoods.setnCaseUnits(tGoods.getCaseUnits());
            tStoreGoods.setnSalePrice(tGoods.getSalePrice());
            tStoreGoods.setnVipPrice(tGoods.getVipPrice());
            tStoreGoods.setsSaleTaxID(tGoods.getSaleTaxID());
            tStoreGoods.setsSaleTax(tGoods.getSaleTax());
            tStoreGoods.setnSaleTaxPct(tGoods.getSaleTaxPct());
            tStoreGoods.setnMainVendorID(tGoods.getMainVendorID());
            tStoreGoods.setnSafeStockDay(tGoods.getSafeStockDay());
            tStoreGoods.setnOPLM(tGoods.getOPLM());
            tStoreGoods.setnStatus(tGoods.getStatus());
            tStoreGoods.setsMainBarcode(tGoods.getMainBarcode());
            tStoreGoods.setnShelfLife(tGoods.getShelfLife());
            tStoreGoods.setnNormalSalePrice(tGoods.getSalePrice());
            tStoreGoods.setnNormalVipPrice(tGoods.getVipPrice());
            tStoreGoods.setsPRSTypeID(null);
            tStoreGoods.setsPromoNO(null);
            tStoreGoods.setnTag(tGoods.getTag());
            tStoreGoods.setsPosTypeID(tGoods.getPosTypeID());
            tStoreGoods.setsPosType(tGoods.getPosType());
            tStoreGoods.setsCreateUser(tGoods.getCreateUser());
            tStoreGoods.setdCreateDate(tGoods.getCreateDate());
            tStoreGoods.setsChangeUser(tGoods.getChangeUser());
            tStoreGoods.setdChangeDate(tGoods.getChangeDate());
            tStoreGoods.setsConfirmUser(tGoods.getConfirmUser());
            tStoreGoods.setdConfirmDate(tGoods.getConfirmDate());
            tStoreGoods.setdLastUpdateTime(tGoods.getLastUpdateTime());
            tStoreGoods.setdEnterDate(tGoods.getEnterDate());
            tStoreGoods.setdSaleBeginDate(null);
            tStoreGoods.setdSaleEndDate(null);
            tStoreGoods.setnBuyPrice(tGoods.getBuyPrice());
            tStoreGoods.setnBuyTaxPct(tGoods.getBuyTaxPct());
            tStoreGoods.setnAvgCostPrice(tGoods.getBuyPrice());
            tStoreGoods.setnPSI(0);
            tStoreGoods.setdUpdateTime(tGoods.getLastUpdateTime());
            tStoreGoods.setnGroup(0);
            tStoreGoods.setnLossRate(tGoods.getLossRate());
            count += tStoreGoodsService.addTStoreGoods(tStoreGoods);
        }
        return count;
    }
}
